import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    bgColor:'red',//保存颜色
    bookList:[],//存放图书
  },
  getters: {
  },
  mutations: {
    // 设置主题
    setBgColor(state){
      console.log(Math.random().toString(16).slice(2,8));
      state.bgColor = '#'+Math.random().toString(16).slice(2,8)
    },
    addBook(state,obj){
      state.bookList.push({
        ...obj,
        status:false,//状态用了表示已读未读
      })
    },
    change(state,id){
        let index = state.bookList.findIndex(item=>item.id == id)
        state.bookList[index].status = !state.bookList[index].status
    },
    del(state,id){
        let index = state.bookList.findIndex(item=>item.id == id)
        state.bookList.splice(index,1)
    }
  },
  actions: {
  },
  modules: {
  }
})
